package model

import (
	"gitee.com/carollia/data-sdk-go/utils"
	"errors"
)

// 礼包
type Bundle struct {
	Type       string                 `json:"type"`
	Time       int64                  `json:"time"`
	BundleId   string                 `json:"bundle_id"`
	Items      [][]int                `json:"items"`  // [][]{ItemId: count, ...}
	Name       string                 `json:"name"`
	Price      float32                `json:"price"`
	Properties map[string]interface{} `json:"properties"`
}


func (b *Bundle) Normalize() error {
	if b.Type != "bundle_set" && b.Type != "bundle_delete" {
		return errors.New("property [Type] is not bundle_set or bundle_delete")
	}
	b.Time = utils.GetCNTimeNow()
	// check uid
	if b.BundleId == "" || len(b.BundleId) == 0 {
		return errors.New("property [ItemId] can't be empty")
	}
	if len(b.BundleId) > 255 {
		return errors.New("the max length of property [ItemId] is 255")
	}
	if len(b.Items) <= 0 {
		return errors.New("property [Items] size should >= 1")
	}

	if b.Properties == nil {
		b.Properties = map[string]interface{}{}
	}
	return nil
}
